package com.shop.clientorder.controller;

import java.util.List;

import com.shop.clientorder.domain.OrderItemVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.shop.common.log.annotation.Log;
import com.shop.common.log.enums.BusinessType;
import com.shop.clientorder.domain.OmsOrderItem;
import com.shop.clientorder.service.IOmsOrderItemService;
import com.shop.common.core.web.controller.BaseController;
import com.shop.common.core.domain.Result;


/**
 * 订单项信息Controller
 *
 * @author czb
 * @date 2024-06-25
 */
@RestController
@RequestMapping("/item")
public class OmsOrderItemController extends BaseController
{
    @Autowired
    private IOmsOrderItemService omsOrderItemService;

/**
 * 查询订单项信息列表
 */
//@RequiresPermissions("clientorder:item:list")
@GetMapping("/list/{orderSn}")
    public Result list(@PathVariable String orderSn)
    {
        startPage();
        List<OmsOrderItem> list = omsOrderItemService.selectOmsOrderItemList(orderSn);
        return getDataTable(list);
    }

    /**
     * 导出订单项信息列表
     */
//    @RequiresPermissions("clientorder:item:export")
//    @Log(title = "订单项信息", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, OmsOrderItem omsOrderItem)
//    {
//        List<OmsOrderItem> list = omsOrderItemService.selectOmsOrderItemList(omsOrderItem);
//        ExcelUtil<OmsOrderItem> util = new ExcelUtil<OmsOrderItem>(OmsOrderItem.class);
//        util.exportExcel(response, list, "订单项信息数据");
//    }

    /**
     * 获取订单项信息详细信息
     */
//    @RequiresPermissions("clientorder:item:query")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id)
    {
        return success(omsOrderItemService.selectOmsOrderItemById(id));
    }

    /**
     * 新增订单和订单项信息
     */
//    @RequiresPermissions("clientorder:item:add")
    @Log(title = "订单项信息", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody OmsOrderItem omsOrderItem)
    {
        return toAjax(omsOrderItemService.insertOmsOrderItem(omsOrderItem));
    }

    @PostMapping("/settlement")
    public Result settlement(@RequestBody OrderItemVo orderItemVo)
    {
        return toAjax(omsOrderItemService.settlementOmsOrderItem(orderItemVo));
    }

    /**
     * 修改订单项信息
     */
//    @RequiresPermissions("clientorder:item:edit")
    @Log(title = "订单项信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody OmsOrderItem omsOrderItem)
    {
        return toAjax(omsOrderItemService.updateOmsOrderItem(omsOrderItem));
    }

    /**
     * 删除订单项信息
     */
//    @RequiresPermissions("clientorder:item:remove")
    @Log(title = "订单项信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids)
    {
        return toAjax(omsOrderItemService.deleteOmsOrderItemByIds(ids));
    }
}
